#ifndef Scenic_Renderer_QuickTimeMediaFile_h
#define Scenic_Renderer_QuickTimeMediaFile_h

#undef DEBUG

#include <movies.h>

#include "SimpleMediaFile.h"
#include "common.h"


namespace Scenic
{
namespace Renderer
{
class QuickTimeMediaFile : public SimpleMediaFile
{
	char *filename;
	Image *image;

	Movie movie;
	GWorldPtr gWorld;
	HBITMAP bitmap;
	HDC dc;
	void *bitmapData;

	HANDLE thread;
	DWORD threadId;
	JNIEnv *threadEnv;
	bool exitThread;
public:
	QuickTimeMediaFile(const char *filename, Image *image);
	~QuickTimeMediaFile();

	void play();
	void pause();
	double getCurrentPosition();
	void setCurrentPosition(double position);
	double getLength();
	void enumerateOutputFormats();
	void setOutputFormat(int width, int height, Format format);
private:
	void createOffscreenGWorld(int width, int height);
	void createThread();
	unsigned long run();
	static unsigned long __stdcall runWrapper(void *data);
	void drawingCallback();
	static short drawingCallbackWrapper(Movie movie, long data);
};

}
}

#endif
